home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / rzstredt / rzstredt.pas < prev    next >
Pascal/Delphi Source File  |  1996-04-08  |  11KB  |  331 lines

  1. {==============================================================================}
  2. {= RzStrEdt - String List Property Editor and Dialog                          =}
  3. {=                                                                            =}
  4. {= This unit file contains a replacement string list property editor and its  =}
  5. {= associated dialog box.  After installing this unit into the Delphi IDE,    =}
  6. {= this editor will be used to edit all string list properties.  To install   =}
  7. {= this editor, follow the same rules used to install a custom component.     =}
  8. {=                                                                            =}
  9. {= Copyright ⌐ 1995 by Raize Software Solutions, Inc.                         =}
  10. {==============================================================================}
  11.  
  12. unit RzStrEdt;
  13.  
  14. interface
  15.  
  16.   uses
  17.     SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  18.     Forms, Dialogs, ExtCtrls, RzPanel, StdCtrls, Buttons, IniFiles, DsgnIntf,
  19.     Menus;
  20.  
  21.   type
  22.     TRzStrListEditorDlg = class( TForm )
  23.       BtnOk         : TBitBtn;
  24.       BtnCancel     : TBitBtn;
  25.       BtnHelp       : TBitBtn;
  26.       PnlToolbar    : TPanel;
  27.       BtnTab        : TSpeedButton;
  28.       BtnOpen       : TSpeedButton;
  29.       BtnSave       : TSpeedButton;
  30.       BtnCut        : TSpeedButton;
  31.       BtnCopy       : TSpeedButton;
  32.       BtnPaste      : TSpeedButton;
  33.       BtnUndo       : TSpeedButton;
  34.       BtnFont       : TSpeedButton;
  35.       PnlStringList : TPanel;
  36.       EdtStrings    : TMemo;
  37.       LblCount      : TLabel;
  38.       ChkDefault    : TCheckBox;
  39.       Label1        : TLabel;
  40.       LblRow        : TLabel;
  41.       Label3        : TLabel;
  42.       LblCol        : TLabel;
  43.       MnuEdit       : TPopupMenu;
  44.       MnuUndo       : TMenuItem;
  45.       MnuCut        : TMenuItem;
  46.       MnuCopy       : TMenuItem;
  47.       MnuPaste      : TMenuItem;
  48.       MnuSep1       : TMenuItem;
  49.       MnuOpen       : TMenuItem;
  50.       MnuSave       : TMenuItem;
  51.       MnuSep2       : TMenuItem;
  52.       MnuTab        : TMenuItem;
  53.       DlgOpen       : TOpenDialog;
  54.       DlgSave       : TSaveDialog;
  55.       DlgFont       : TFontDialog;
  56.       LblCopyright: TLabel;
  57.       BtnCopyright: TButton;
  58.       procedure FormCreate( Sender : TObject );
  59.       procedure BtnOkClick( Sender : TObject );
  60.       procedure BtnFontClick( Sender : TObject );
  61.       procedure BtnUndoClick( Sender : TObject );
  62.       procedure BtnCutClick( Sender : TObject );
  63.       procedure BtnCopyClick( Sender : TObject );
  64.       procedure BtnPasteClick( Sender : TObject );
  65.       procedure BtnOpenClick( Sender : TObject );
  66.       procedure BtnSaveClick( Sender : TObject );
  67.       procedure BtnTabClick( Sender : TObject );
  68.       procedure EdtStringsChange( Sender : TObject );
  69.       procedure EdtStringsKeyDown( Sender : TObject; var Key : Word;
  70.                                    Shift : TShiftState );
  71.       procedure EdtStringsKeyUp( Sender : TObject; var Key : Word;
  72.                                  Shift : TShiftState );
  73.       procedure EdtStringsClick( Sender : TObject);
  74.       procedure BtnCopyrightClick(Sender: TObject);
  75.     private
  76.       SingleLine    : string[ 15 ];
  77.       MultipleLines : string[ 15 ];
  78.       DelphiIni     : TIniFile;
  79.       procedure UpdateClipboardStatus;
  80.     end;
  81.  
  82.   type
  83.     TRzStringListProperty = class( TPropertyEditor )
  84.       function GetAttributes : TPropertyAttributes; override;
  85.       function GetValue: string; override;
  86.       procedure Edit; override;
  87.     end;
  88.  
  89.   procedure Register;
  90.  
  91. implementation
  92.  
  93. {$R *.DFM}
  94.  
  95.   uses
  96.     LibConst, LibHelp, ClipBrd;
  97.  
  98.   const                               { Constants used to determine font style }
  99.     fsBoldMask      = 8;
  100.     fsItalicMask    = 4;
  101.     fsUnderlineMask = 2;
  102.     fsStrikeOutMask = 1;
  103.  
  104.   procedure TRzStrListEditorDlg.FormCreate(Sender: TObject);
  105.   var
  106.     StyleBits  : Byte;
  107.   begin
  108.     HelpContext := hcDStringListEditor;
  109.  
  110.     DlgOpen.HelpContext := hcDStringListLoad;
  111.     DlgSave.HelpContext := hcDStringListSave;
  112.     SingleLine := LoadStr( srLine );
  113.     MultipleLines := LoadStr( srLines );
  114.  
  115.     DelphiIni := TIniFile.Create( 'DELPHI.INI' );
  116.     with EdtStrings.Font do
  117.     begin
  118.       Name := DelphiIni.ReadString( 'Raize.StrListEditor', 'FontName',
  119.                                     'MS Sans Serif' );
  120.       Size := DelphiIni.ReadInteger( 'Raize.StrListEditor', 'FontSize', 8 );
  121.       Color := DelphiIni.ReadInteger( 'Raize.StrListEditor', 'FontColor', clBlack );
  122.       StyleBits := DelphiIni.ReadInteger( 'Raize.StrListEditor', 'FontStyle', fsBoldMask );
  123.       Style := [];
  124.       if StyleBits and fsBoldMask = fsBoldMask then
  125.         Style := Style + [ fsBold ];
  126.       if StyleBits and fsItalicMask = fsItalicMask then
  127.         Style := Style + [ fsItalic ];
  128.       if StyleBits and fsUnderlineMask = fsUnderlineMask then
  129.         Style := Style + [ fsUnderline ];
  130.       if StyleBits and fsStrikeOutMask = fsStrikeOutMask then
  131.         Style := Style + [ fsStrikeOut ];
  132.     end;
  133.     UpdateClipboardStatus;
  134.   end; {= TRzStrListEditorDlg.FormCreate =}
  135.  
  136.  
  137.   procedure TRzStrListEditorDlg.BtnOkClick(Sender: TObject);
  138.   var
  139.     StyleBits : Byte;
  140.   begin
  141.     if ChkDefault.Checked then
  142.     begin
  143.       with EdtStrings.Font do
  144.       begin
  145.         DelphiIni.WriteString( 'Raize.StrListEditor', 'FontName', Name );
  146.         DelphiIni.WriteInteger( 'Raize.StrListEditor', 'FontSize', Size );
  147.         DelphiIni.WriteInteger( 'Raize.StrListEditor', 'FontColor', Color );
  148.  
  149.         if fsBold in Style then
  150.           StyleBits := fsBoldMask;
  151.         if fsItalic in Style then
  152.           StyleBits := StyleBits + fsItalicMask;
  153.         if fsUnderline in Style then
  154.           StyleBits := StyleBits + fsUnderlineMask;
  155.         if fsStrikeOut in Style then
  156.           StyleBits := StyleBits + fsStrikeOutMask;
  157.         DelphiIni.WriteInteger( 'Raize.StrListEditor', 'FontStyle', StyleBits );
  158.       end;
  159.     end;
  160.     DelphiIni.Free;
  161.   end; {= TRzStrListEditorDlg.BtnOkClick =}
  162.  
  163.  
  164.   procedure TRzStrListEditorDlg.BtnFontClick(Sender: TObject);
  165.   begin
  166.     DlgFont.Font := EdtStrings.Font;
  167.     if DlgFont.Execute then
  168.     begin
  169.       EdtStrings.Font := DlgFont.Font;
  170.     end;
  171.   end; {= TRzStrListEditorDlg.BtnFontClick =}
  172.  
  173.  
  174.   procedure TRzStrListEditorDlg.BtnUndoClick(Sender: TObject);
  175.   begin
  176.     EdtStrings.Perform( wm_Undo, 0, 0 );
  177.   end; {= TRzStrListEditorDlg.BtnUndoClick =}
  178.  
  179.  
  180.   procedure TRzStrListEditorDlg.BtnCutClick(Sender: TObject);
  181.   begin
  182.     EdtStrings.CutToClipboard;
  183.     UpdateClipboardStatus;
  184.   end; {= TRzStrListEditorDlg.BtnCutClick =}
  185.  
  186.  
  187.   procedure TRzStrListEditorDlg.BtnCopyClick(Sender: TObject);
  188.   begin
  189.     EdtStrings.CopyToClipboard;
  190.     UpdateClipboardStatus;
  191.   end; {= TRzStrListEditorDlg.BtnCopyClick =}
  192.  
  193.  
  194.   procedure TRzStrListEditorDlg.BtnPasteClick(Sender: TObject);
  195.   begin
  196.     EdtStrings.PasteFromClipboard;
  197.   end; {= TRzStrListEditorDlg.BtnPasteClick =}
  198.  
  199.  
  200.   procedure TRzStrListEditorDlg.BtnOpenClick(Sender: TObject);
  201.   begin
  202.     if DlgOpen.Execute then
  203.       EdtStrings.Lines.LoadFromFile( DlgOpen.FileName );
  204.   end; {= TRzStrListEditorDlg.BtnOpenClick =}
  205.  
  206.  
  207.   procedure TRzStrListEditorDlg.BtnSaveClick(Sender: TObject);
  208.   begin
  209.     if DlgSave.Execute then
  210.       EdtStrings.Lines.SaveToFile( DlgSave.FileName );
  211.   end; {= TRzStrListEditorDlg.BtnSaveClick =}
  212.  
  213.  
  214.   procedure TRzStrListEditorDlg.BtnTabClick(Sender: TObject);
  215.   begin
  216.     EdtStrings.Perform( wm_Char, vk_tab, 0 );
  217.   end; {= TRzStrListEditorDlg.BtnTabClick =}
  218.  
  219.  
  220.   procedure TRzStrListEditorDlg.EdtStringsChange(Sender: TObject);
  221.   var
  222.     Count    : Integer;
  223.     LineText : PString;
  224.   begin
  225.     Count := EdtStrings.Lines.Count;
  226.     if Count = 1 then
  227.       LineText := @SingleLine
  228.     else
  229.       LineText := @MultipleLines;
  230.     LblCount.Caption := Format( '%d %s', [ Count, LineText^ ] );
  231.     EdtStringsClick( Sender );
  232.   end; {= TRzStrListEditorDlg.EdtStringsChange =}
  233.  
  234.  
  235.   procedure TRzStrListEditorDlg.EdtStringsKeyDown(Sender: TObject;
  236.     var Key: Word; Shift: TShiftState);
  237.   begin
  238.     EdtStringsClick( Sender );
  239.     if Key = vk_Escape then
  240.       BtnCancel.Click;
  241.   end; {= TRzStrListEditorDlg.EdtStringsKeyDown =}
  242.  
  243.  
  244.   procedure TRzStrListEditorDlg.EdtStringsKeyUp(Sender: TObject;
  245.     var Key: Word; Shift: TShiftState);
  246.   begin
  247.     EdtStringsClick( Sender );
  248.   end; {= TRzStrListEditorDlg.EdtStringsKeyUp =}
  249.  
  250.  
  251.   procedure TRzStrListEditorDlg.EdtStringsClick(Sender: TObject);
  252.   var
  253.     X, Y : LongInt;
  254.   begin
  255.     Y := EdtStrings.Perform( em_LineFromChar, EdtStrings.SelStart, 0 );
  256.     X := EdtStrings.SelStart - EdtStrings.Perform( em_LineIndex, Y, 0 );
  257.     LblRow.Caption := IntToStr( Y + 1 );
  258.     LblCol.Caption := IntToStr( X + 1 );
  259.     UpdateClipboardStatus;
  260.   end; {= TRzStrListEditorDlg.EdtStringsClick =}
  261.  
  262.  
  263.   procedure TRzStrListEditorDlg.UpdateClipboardStatus;
  264.   var
  265.     HasText      : Boolean;
  266.     HasSelection : Boolean;
  267.   begin
  268.     HasSelection := EdtStrings.SelLength <> 0;
  269.     BtnCut.Enabled := HasSelection;
  270.     MnuCut.Enabled := HasSelection;
  271.     BtnCopy.Enabled := HasSelection;
  272.     MnuCopy.Enabled := HasSelection;
  273.     HasText := Clipboard.HasFormat( cf_Text );
  274.     BtnPaste.Enabled := HasText;
  275.     MnuPaste.Enabled := HasText;
  276.   end; {= TRzStrListEditorDlg.UpdateClipboardStatus =}
  277.  
  278.  
  279.   procedure TRzStrListEditorDlg.BtnCopyrightClick(Sender: TObject);
  280.   begin
  281.     LblCopyright.Visible := True;
  282.   end; {= TRzStrListEditorDlg.BtnCopyrightClick =}
  283.  
  284.  
  285.  
  286.   {===================================}
  287.   {== TRzStringListProperty Methods ==}
  288.   {===================================}
  289.  
  290.   function TRzStringListProperty.GetAttributes: TPropertyAttributes;
  291.   begin
  292.     Result := inherited GetAttributes + [paDialog] - [paSubProperties];
  293.   end; {= TRzStringListProperty.GetAttributes =}
  294.  
  295.  
  296.   function TRzStringListProperty.GetValue : string;
  297.   begin
  298.     FmtStr( Result, '(%s)', [ GetPropType^.Name ] );
  299.   end; {= TRzStringListProperty.GetValue =}
  300.  
  301.  
  302.   procedure TRzStringListProperty.Edit;
  303.   var
  304.     Dlg : TRzStrListEditorDlg;
  305.   begin
  306.     with TRzStrListEditorDlg.Create( Application ) do
  307.     begin
  308.       try
  309.         EdtStrings.Lines := TStringList( GetOrdValue );
  310.         EdtStringsClick( nil );
  311.         if ( ShowModal = mrOK ) and ( EdtStrings.Modified ) then
  312.           SetOrdValue( Longint( EdtStrings.Lines ) );
  313.       finally
  314.         Free;
  315.       end;
  316.     end; { with }
  317.   end; {= TRzStringListProperty.Edit =}
  318.  
  319.  
  320.   {========================}
  321.   {== Register Procedure ==}
  322.   {========================}
  323.  
  324.   procedure Register;
  325.   begin
  326.     RegisterPropertyEditor( TypeInfo( TStrings ), nil, '',
  327.                             TRzStringListProperty );
  328.   end;
  329.  
  330. end.
  331.